﻿
function SessionManager() {

    var sessionTime = 0;
    var seconds = 60;

    var isStartTimer = 'true';
    var objectTimer;

    this.Start = function (time)
    {
        sessionTime = time;
        seconds = sessionTime * 60;
        objectTimer = setInterval(function () { DisplaySessionTimer() }, 1000);
    }

    function DisplaySessionTimer ()
    {
        //var minutes = Math.round((seconds - 30) / 60);
        //var remainingSeconds = seconds % 60;
        //if (remainingSeconds < 10) {
        //    remainingSeconds = "0" + remainingSeconds;
        //}
        //document.getElementById('sessiontimer').innerHTML = minutes + ":" + remainingSeconds;        
        //console.log("Session Expire in: "+seconds +" sec");

        if (seconds == 0) {
            console.log('Session Expired!');
            var login = getCookie('Login');
            var Guid = getCookie('GUID');
            if (Guid)
                window.location = '../../' + login + '.aspx?Guid=' + Guid;
            else
                window.location = '../../' + login + '.aspx';
        } else {
            seconds--;
        }        
    }   

    this.Stop = function ()
    {
        clearInterval(objectTimer);
    }
   
    function getCookie (cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i].trim();
            if (c.indexOf(name) == 0)
                return c.substring(name.length, c.length);
        }
        return "";
    }
}